Skip to content

Add async methods to OpenXmlReader#2075

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/add-async-xmlreader-methods
Draft

Add async methods to OpenXmlReader#2075
Copilot wants to merge 6 commits intomainfrom
copilot/add-async-xmlreader-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

OpenXmlReader had no async API despite OpenXmlWriter having full async support. This adds parity by introducing ReadAsync, ReadFirstChildAsync, ReadNextSiblingAsync, and SkipAsync.

Changes

  • OpenXmlReader (base class) — virtual async methods that fall back to their sync counterparts (same pattern as OpenXmlWriter); guarded by #if TASKS_SUPPORTED so net35/net40 are unaffected
  • OpenXmlPartReaderOptions — new Async property (mirrors OpenXmlPartWriterSettings.Async); propagated through UpdateForPart and forwarded to XmlReaderSettings.Async
  • OpenXmlPartReader — truly async overrides backed by XmlReader.ReadAsync/SkipAsync/MoveToContentAsync; private async helpers mirror the existing sync MoveToNextElement/MoveToFirstChild/InnerSkip/ReadRoot logic
  • XmlConvertingReader — overrides ReadAsync, SkipAsync, MoveToContentAsync to delegate to BaseReader (the wrapper would otherwise fall through to the throwing base XmlReader default)
  • Public API — unshipped entries added for netstandard2.0, net6.0, net8.0, net10.0

Usage

// Enable async mode when constructing the reader
using var reader = new OpenXmlPartReader(part, new OpenXmlPartReaderOptions { Async = true });

while (await reader.ReadAsync())
{
    if (reader.IsStartElement)
    {
        // navigate
        await reader.ReadFirstChildAsync();
        await reader.ReadNextSiblingAsync();
        await reader.SkipAsync();
    }
}

OpenXmlDomReader works with the same async API via the base-class fallbacks (no Async flag required).

Copilot AI linked an issue Apr 28, 2026 that may be closed by this pull request
- Add virtual async methods (ReadAsync, ReadFirstChildAsync, ReadNextSiblingAsync, SkipAsync) to OpenXmlReader base class, guarded by FEATURE_ASYNC_SAX_XML
- Add Async property to OpenXmlPartReaderOptions (FEATURE_ASYNC_SAX_XML only)
- Update OpenXmlPartReader.CreateReader to accept OpenXmlPartReaderOptions and pass Async to XmlReaderSettings
- Add async override implementations in OpenXmlPartReader using XmlReader.ReadAsync, SkipAsync, MoveToContentAsync
- Add ReadAsync, SkipAsync, MoveToContentAsync overrides in XmlConvertingReader to delegate to BaseReader
- Update PublicAPI unshipped files for netstandard2.0, net6.0, net8.0, net10.0
- Add OpenXmlReaderAsyncTest with 13 async tests covering both OpenXmlPartReader and OpenXmlDomReader scenarios

Agent-Logs-Url: https://github.com/dotnet/Open-XML-SDK/sessions/1107ecf6-458c-498d-b45c-f7b3d6eeb5fc

Co-authored-by: twsouthwick <[email protected]>
Copilot AI changed the title [WIP] Add async XmlReader methods for OpenXmlReader Add async methods to OpenXmlReader Apr 28, 2026
Copilot AI requested a review from twsouthwick April 28, 2026 17:13
@github-actions
Copy link
Copy Markdown

Test Results

    51 files   -     29      51 suites   - 29   52m 4s ⏱️ - 42m 23s
 2 091 tests +    13   2 088 ✅ +    13   3 💤 ± 0  0 ❌ ±0 
24 404 runs   - 13 769  24 377 ✅  - 13 754  27 💤  - 15  0 ❌ ±0 

Results for commit 1a8cc72. ± Comparison against base commit 7d1bd90.

@mikeebowen
Copy link
Copy Markdown
Collaborator

@copilot fix the build errors from the previous build

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot fix the build errors from the previous build

Fixed in 94cd2ca. The build failures were SA1515 StyleCop errors in OpenXmlReaderAsyncTest.cs — single-line comments at lines 105 and 107 were not preceded by blank lines. Added the required blank lines before each comment.

Copilot AI requested a review from mikeebowen April 29, 2026 20:59
@mikeebowen
Copy link
Copy Markdown
Collaborator

@copilot refactor the tests to use using statements

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot refactor the tests to use using statements

Done in 59c3b0a. All tests now use traditional using (...) { } blocks with braces, matching the pattern in the existing OpenXmlReaderTest.cs and OpenXmlWriterTest.cs files.

@mikeebowen
Copy link
Copy Markdown
Collaborator

@copilot refactor FEATURE_ASYNC_SAX_XML to be TASKS_SUPPORTED

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot refactor FEATURE_ASYNC_SAX_XML to be TASKS_SUPPORTED

Done in 7aa9cc0. Renamed FEATURE_ASYNC_SAX_XML to TASKS_SUPPORTED in all 10 files: Directory.Build.props, OpenXmlReader.cs, OpenXmlPartReader.cs, OpenXmlPartReaderOptions.cs, OpenXmlWriter.cs, OpenXmlPartWriter.cs, OpenXmlPartWriterSettings.cs, XmlConvertingReader.cs, and both test files.

@mikeebowen mikeebowen requested a review from tomjebo May 5, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Async XmlReader methods

3 participants